import QtQuick 2.0

Item {
    id: slide
    width: 100
    height: img.height
    property alias source: img.source
    property int xStart: -50
    property int yStart: -50
    property int xEnd: 50
    property int yEnd: 50
    property double scaleStart: 0.9
    property double scaleEnd: 1.1
    property int duration: 10000
    property bool started: false
    signal slideShowed();
    function startAnimation() {
        img.x = xStart
        img.y = yStart
        img.scale = scaleStart
        xAnim.to = xEnd;
        yAnim.to = yEnd;
        scaleAnim.to = scaleEnd;
        anim.start()
    }
    function stopAnimation() { anim.running = false; }

    Image {
        id: img
        width: slide.width
        fillMode: Image.PreserveAspectFit
        onStatusChanged: {
            if (img.status == Image.Null || img.status == Image.Error)
                slideShowed();
        }
    }


    ParallelAnimation {
        id: anim;
        onRunningChanged: if (running == false) fadeOutAnim.start()
        NumberAnimation { target: img; property: "opacity"; to: 1.0; duration: slide.duration/4; easing.type: Easing.InOutQuad }
        NumberAnimation { id: xAnim; target: img; property: "x"; duration: slide.duration; easing.type: Easing.InOutQuad }
        NumberAnimation { id: yAnim; target: img; property: "y"; duration: slide.duration; easing.type: Easing.InOutQuad }
        NumberAnimation { id: scaleAnim; target: img; property: "scale"; duration: slide.duration; easing.type: Easing.InOutQuad }
    }
    NumberAnimation {
        id: fadeOutAnim; target: img; property: "opacity"; to: 0.0;
        onRunningChanged: if (running == false) slide.slideShowed();
        duration: 1500; easing.type: Easing.OutExpo
    }
}
